package com.bili.bili_data_api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bili.bili_data_api.dao.mapper.PingfenMapper;
import com.bili.bili_data_api.dao.pojo.Pingfen;
import com.bili.bili_data_api.service.PingfenService;
import com.bili.bili_data_api.vo.PingfenVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class PingfenServiceImpl implements PingfenService {

    @Autowired
    private PingfenMapper pingfenMapper;

    @Override
    public PingfenVo getRating() {

        PingfenVo pingfenVo = new PingfenVo();
        QueryWrapper<Pingfen> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("score");
        List<Pingfen> pingfenList = pingfenMapper.selectList(queryWrapper);
        List<String> scores = new ArrayList<String>();
        List<Integer> nums = new ArrayList<Integer>();
        for (Pingfen pingfen : pingfenList) {
            scores.add(pingfen.getScore());
            nums.add(pingfen.getNum());
        }
        pingfenVo.setScoreList(scores);
        pingfenVo.setNumList(nums);
        return pingfenVo;
    }
}
